package com.wh1200.mybatis.xmlless.resolver

import com.wh1200.mybatis.xmlless.config.BaseResolverTest
import com.wh1200.xmlless.test.dao.StudentDAO
import org.junit.jupiter.api.Test
import kotlin.reflect.jvm.javaMethod
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

/**
 * Created by 吴昊 on 2018/12/19.
 */
class ParameterResolverTest : BaseResolverTest(
    StudentDAO::class.java
) {

  @Test
  fun resolve2() {
    val methodInfo = createMethodInfo(StudentDAO::find4.javaMethod!!)
    val result = ParameterResolver.resolve(
        "currentUserId", methodInfo
    )
    assertNotNull(result)
    assertEquals("form.currentUserId", result.name)
  }

  @Test
  fun resolveDistinctProperty() {
    val q = createQueryForMethod(StudentDAO::select.javaMethod!!)
    q.exception?.printStackTrace()
    println(q.sql)
  }

  @Test
  fun resolve() {
    val methodInfo = createMethodInfo(StudentDAO::find3.javaMethod!!)
    val result = ParameterResolver.resolve(
        "start", methodInfo
    )
    assertNotNull(result)
    assertEquals("start", result.name)
  }


  @Test
  fun resolveNames() {
    val result = ParameterResolver.resolveNames(StudentDAO::findByAgeBetweenMinAndMaxOrderByBirthday.javaMethod!!)
    assertEquals(2, result.size)
    assertEquals("min", result[0])
    assertEquals("max", result[1])
  }


}
